<?php

namespace apiend\modules\v1\controllers;

use Yii;
use apiend\components\Controller;
// use api\models\UploadImage;
// use yii\web\UploadedFile;
use common\helpers\FileHelper;

class ImageController extends Controller {

    public function actionLog() {
        $path = Yii::getAlias('@uploads');
        return ['path' => $path];
    }

    public function actionUpload() {
        if (Yii::$app->request->isPost) {
            $data = FileHelper::upload();
            return $data;
        }

        throw new \yii\web\HttpException(418, '请求方法不允许');
    }

    public function actionCompress() {
        $uploadBasePath = Yii::getAlias('@uploads');
        $uploadPath = '/attachments/' . 'default' . '/' . '201804/03' . '/' . 'cat.jpg';
        $absolutePath = $uploadBasePath . $uploadPath;
        $source = $absolutePath;
        $filename = 'cat.jpg';
        $info = FileHelper::imgCompress($source, $filename);
        return $info;
    }

}
